﻿@{
    ViewData["Title"] = "Privacy Policy";
}
<div class="page preview js_show">
    <div class="page__hd">
        <h1 class="page__title">生产计划列表</h1>
        <p class="page__desc">请选择要进行配盘的计划。</p>
    </div>
    <div class="page__bd" id="tt_container">
        
    </div>
</div>

<script type="text/template" id="tthtml">
    <div class="weui-form-preview">
        <div role="option" class="weui-form-preview__hd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">生产筒型</label>
                <em class="weui-form-preview__value">{{name}}</em>
            </div>
        </div>
        <div role="option" aria-labelledby="p1 js_a11y_comma p2 js_a11y_comma p3" class="weui-form-preview__bd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">物料编码</label>
                <span class="weui-form-preview__value">{{code}}</span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">计划数量</label>
                <span class="weui-form-preview__value">{{count}}个</span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">实际生产</label>
                <span class="weui-form-preview__value">{{quantity}}个</span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">计划日期</label>
                <span class="weui-form-preview__value">{{planDate}}</span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">计划状态</label>
                <span class="weui-form-preview__value">{{status}}</span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">配送状态</label>
                <span class="weui-form-preview__value">{{deliveryState}}</span>
            </div>
        </div>
        <div class="weui-form-preview__ft">
            <a role="button" class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:StartPlan('{{id}}')">开始执行计划</a>
        </div>
    </div>
    <br>
</script>
<script type="text/template" id="ttempty">
    <p class="weui-msg__desc" style="color:red; text-align:center; margin:50px;">暂无生产计划<br />请联系管理人中下发生产计划</p>
</script>
<script type="text/javascript">
    var _url = "http://192.168.98.127:8020/CtrPms";

    function StartPlan(id) {
        if (confirm("确定开始执行当前计划吗？")) {
            $.ajax({
                url: _url + "/StartPlan?id="+id
                , success: function (nid) {
                    if (nid == id) {
                        alert("开始执行计划成功");
                        window.location.href = "@Url.Action("Index")";
                    }
                    else {
                        alert("开始执行计划失败");
                    }
                }
            });
        }
    }

    function LoadData() {
        $.ajax({
            url: _url +"/PlanList"
            , success: function (data) {
                var temp = $("#tthtml").html();
                var itemStr = "";
                $("#tt_container").html("");
                $(data).each(function (idx) {
                    var item = this;
                    itemStr = temp;

                    itemStr = itemStr.replace("{{name}}", item.name);
                    itemStr = itemStr.replace("{{code}}", item.code);
                    itemStr = itemStr.replace("{{count}}", item.count);
                    itemStr = itemStr.replace("{{quantity}}", item.quantity);
                    itemStr = itemStr.replace("{{planDate}}", item.planDate);
                    itemStr = itemStr.replace("{{status}}", statusName(item.status));
                    itemStr = itemStr.replace("{{deliveryState}}", deliveryStateName(item.deliveryState));
                    itemStr = itemStr.replace("{{id}}", item.id);

                    $("#tt_container").html($("#tt_container").html() + itemStr);
                });

                if ($("#tt_container").html() == "") {
                    $("#tt_container").html($("#ttempty").html());
                }
            }
        });
    }

    function statusName(status) {
        if (status == 1) {
            return "已下发";
        }
        else if (status == 2) {
            return "执行中";
        }
        else if (status == 3) {
            return "生产完成";
        }
        else if (status == 4) {
            return "强制办结";
        }
        else if (status == 0) {
            return "编制";
        }
        else {
            return "";
        }
    }

    function deliveryStateName(status) {
        if (status == 0) {
            return "未开始";
        }
        else if (status == 1) {
            return "执行中";
        }
        else if (status == 2) {
            return "配送完成";
        }
        else {
            return "";
        }
    }

    LoadData();
</script>
